package com.example.mall.web.controller;

import com.example.mall.domain.ProductDelistings;
import com.example.mall.dto.ProductDelistingsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.ProductDelistingsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IProductDelistingsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productDelistings")
public class ProductDelistingsController {

    @Autowired
    public IProductDelistingsService productDelistingsService;

    /**
     * 分页查询商品下架记录表信息
     * @param productDelistingsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询商品下架记录表信息",notes = "分页查询商品下架记录表信息",httpMethod = "GET")
    public JSONResult queryPage(ProductDelistingsQuery productDelistingsQuery){
        PageDTO<ProductDelistingsDto> productDelistingsDtoPageDTO = productDelistingsService.queryPage(productDelistingsQuery);
        return JSONResult.success("查询成功",productDelistingsDtoPageDTO);
    }

    /**
     * 根据id查询商品下架记录表信息
     * @param delistId
     * @return
     */
    @GetMapping("query/{delistId}")
    @ApiOperation(value = "根据id查询商品下架记录表信息",notes = "根据id查询商品下架记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("delistId")Long delistId){
        //1.根据id查询用户信息
        if (delistId == null){
            throw new GlobalCustomerException(ErrorEnumCode.DELISTID_NOT_ID);
        }
        ProductDelistings productDelistings = productDelistingsService.getById(delistId);
        return JSONResult.success("查询成功",productDelistings);
    }

    /**
     * 根据id查询商品下架记录表信息
     * @param delistId
     * @return
     */
    @GetMapping("queryProductDelistingsById/{delistId}")
    @ApiOperation(value = "根据id查询商品下架记录表信息",notes = "根据id查询商品下架记录表信息",httpMethod = "GET")
    public JSONResult queryProductDelistingsById(@PathVariable("delistId")Long delistId){
        //1.根据id查询用户信息
        if (delistId == null){
            throw new GlobalCustomerException(ErrorEnumCode.DELISTID_NOT_ID);
        }
        ProductDelistings productDelistings = productDelistingsService.queryProductDelistingsById(delistId);
        return JSONResult.success("查询成功",productDelistings);
    }

    /**
     * 查询全部商品下架记录表信息
     * @param
     * @return
     */
    @GetMapping("queryProductDelistingsList")
    @ApiOperation(value = "查询全部商品下架记录表信息",notes = "查询全部商品下架记录表信息",httpMethod = "GET")
    public JSONResult queryProductDelistingsList(){
        List<ProductDelistings> productDelistings = productDelistingsService.queryProductDelistingsList();
        return JSONResult.success("查询成功",productDelistings);
    }

    /**
     * 新增商品下架记录表
     * @param productDelistingsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增商品下架记录表",notes = "新增商品下架记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody ProductDelistingsDto productDelistingsDto){
        productDelistingsService.insert(productDelistingsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改商品下架记录表信息
     * @param productDelistingsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改商品下架记录表信息",notes = "修改商品下架记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody ProductDelistingsDto productDelistingsDto){
        productDelistingsService.update(productDelistingsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除商品下架记录表信息
     * @param delistId
     * @return
     */
    @PostMapping("delete/{delistId}")
    @ApiOperation(value = "删除商品下架记录表信息",notes = "删除商品下架记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("delistId") Long delistId) {
        productDelistingsService.delete(delistId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除商品下架记录表信息
     * @param delistIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除商品下架记录表信息",notes = "批量删除商品下架记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> delistIds) {
        productDelistingsService.deleteBatch(delistIds);
        return JSONResult.success("批量删除成功");
    }
}
